﻿using System;
using System.Windows.Data;
using System.Globalization;
using System.Windows.Controls;
using System.Drawing;

namespace StockholmsStad.Windows.UI.Infrastructure.Converters
{
    public sealed class BackgroundConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var item = (ListViewItem) value;
            var listView = ItemsControl.ItemsControlFromItemContainer(item) as ListView;

            // Get the index of a ListViewItem
            if (listView != null)
            {
                int index = listView.ItemContainerGenerator.IndexFromContainer(item);

                if (index%2 == 0)
                    return Brushes.LightBlue;
            }

            return Brushes.Beige;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion
    }
}